//
//  CALayer+UIColor.m
//  MYKLC
//
//  Created by Mac on 2018/6/13.
//  Copyright © 2018年 yangkang. All rights reserved.
//

#import "CALayer+EXT.h"

@implementation CALayer (EXT)

///**
// 用UIColor设置边框颜色
// */
//- (void)setBorderUIColor:(UIColor *)color {
//    self.borderColor = color.CGColor;
//}
//
///**
// 用UIColor设置阴影颜色
// */
//- (void)setShadowUIColor:(UIColor *)color {
//    self.shadowColor = color.CGColor;
//}

/**
 缩放动画
 
 @param duration 动画时间
 */
- (void)myk_animationWithEaseInEaseOutDuration:(CFTimeInterval)duration {
    CAKeyframeAnimation * animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    
    animation.duration = duration;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    
    NSMutableArray *values = [NSMutableArray array];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    
    animation.values = values;
    animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
    
    [self addAnimation:animation forKey:nil];
}

// 旋转动画
- (void)myk_addRotationAnimation:(CGFloat)fromValue
                     toValue:(CGFloat)toValue
                    duration:(NSTimeInterval)duration {
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = [NSNumber numberWithFloat:fromValue];
    animation.toValue = [NSNumber numberWithFloat: toValue];
    animation.duration = duration;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = 1;
    [self addAnimation:animation forKey:nil];
}

@end
